import { createRouter, createWebHashHistory } from 'vue-router'
// import { useAppStore } from '@/store/modules/app'
// const AppStore = useAppStore()
const router = createRouter({
  history: createWebHashHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'layout',
      redirect: '/login',
      component: () => import('../views/layout/layout.vue'),
      meta: {
        title: '组件'
      },
      children: [
        {
          path: 'newTask',
          name: 'newTask',
          component: () => import('../views/newTask/newTask.vue'),
          meta: {
            title: '最新任务',
            keepAlive: true
          }
        },
        {
          path: 'myTask',
          name: 'myTask',
          component: () => import('../views/myTask/myTask.vue'),
          meta: {
            title: '我的任务',
            keepAlive: true
          }
        },
        {
          path: 'mine',
          name: 'mine',
          component: () => import('../views/mine/mine.vue'),
          meta: {
            title: '个人中心'
          }
        }
      ]
    },
    {
      path: '/followFeedback',
      name: 'followFeedback',
      component: () => import('../views/FollowFeedback/FollowFeedback.vue'),
      meta: {
        title: '跟踪反馈'
      }
    },
    {
      path: '/followHistory',
      name: 'followHistory',
      component: () => import('../views/FollowFeedback/followHistory.vue'),
      meta: {
        title: '跟进历史'
      }
    },
    {
      path: '/userInfo',
      name: 'userInfo',
      component: () => import('../views/mine/userInfo.vue'),
      meta: {
        title: '用户信息'
      }
    },
    {
      path: '/changePassword',
      name: 'changePassword',
      component: () => import('../views/mine/changePassword.vue'),
      meta: {
        title: '修改密码'
      }
    },
    {
      path: '/addTask',
      name: 'addTask',
      component: () => import('../views/myTask/addTask.vue'),
      meta: {
        title: '新增任务'
      }
    },
    {
      path: '/search',
      name: 'search',
      component: () => import('../views/search/search.vue'),
      meta: {
        title: '新增任务'
      }
    },
    {
      path: '/login',
      name: 'login',
      component: () => import('../views/login/login.vue')
    },
    {
      path: '/richtext',
      name: 'richText',
      component: () => import('../views/realName/richText.vue'),
      meta: {
        title: '展业承诺书'
      }
    },
    {
      path: '/cardPage',
      name: 'cardPage',
      component: () => import('../views/realName/cardPage.vue'),
      meta: {
        title: '上传身份证'
      }
    },
    {
      path: '/faceDetect',
      name: 'faceDetect',
      component: () => import('../views/realName/FaceDetect.vue'),
      meta: {
        title: '人脸识别'
      }
    },
    {
      path: '/esign',
      name: 'esign',
      component: () => import('../views/realName/esignView.vue'),
      meta: {
        title: '签名确认'
      }
    },
    {
      path: '/commitment',
      name: 'commitment',
      component: () => import('../views/mine/commitment.vue'),
      meta: {
        title: '展业承诺书'
      }
    },
    {
      path: '/agreement',
      name: 'agreement',
      component: () => import('../views/mine/agreement.vue'),
      meta: {
        title: '我的协议'
      }
    }
  ]
})

// router.beforeResolve(async to => {
//   console.log(to)
//   // console.log(AppStore)
// })

export const resetRouter = (): void => {
  const resetWhiteNameList = ['Redirect']
  router.getRoutes().forEach((route) => {
    const { name } = route
    if (name && !resetWhiteNameList.includes(name as string)) {
      router.hasRoute(name) && router.removeRoute(name)
    }
  })
}

export default router
